package ypmits.components {
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;

	/**
	 * @author Dave Lenz
	 */
	public class Component extends Sprite {

		protected var _text : String;
		public var textfield : TextField;
		protected var skin : ComponentSkin = null;

		
		
		public function Component( skin : ComponentSkin = null ) 
		{
			skin ? this.skin = skin : skin = new ComponentSkin();
			
			addEventListener( Event.ADDED_TO_STAGE, init );

			blendMode = BlendMode.LAYER;
		}

		
		
		private function init( e : Event ) : void 
		{
			removeEventListener( Event.ADDED_TO_STAGE, init );
			build( );
		}

		
		
		public function build() : void 
		{
		}

		
		
		public function getTextField() : TextField 
		{
			return textfield;
		}

		
		
		public function setTextFormat( format : TextFormat ) : void 
		{
			if( textfield ) {
				textfield.setTextFormat( format );
				textfield.defaultTextFormat = format;
			}
		}

		
		
		public function validate() : Boolean 
		{
			return false;
		}

		
		
		public function dispose() : void 
		{
		}

		
		
		public function show() : void 
		{
			alpha = 1;
			visible = true;
		}

		
		
		public function hide() : void 
		{
			alpha = 0;
			visible = false;
		}

		
		
		public function reset() : void 
		{
		}
		
		
		
		public function enable() : void 
		{
			mouseChildren = mouseEnabled = true;
		}

		
		
		public function disable() : void 
		{
			mouseChildren = mouseEnabled = false;
		}

		
		
		/*
		 * GETTERS EN SETTERS
		 */
		public function get text() : String 
		{
			return _text;
		}

		
		
		public function set text( t : String ) : void {
			_text = t;
			if( textfield ) textfield.text = t;
		}

		
		
		public function get restrict() : String 
		{
			return textfield.restrict;
		}

		
		
		public function set restrict( r : String ) : void {
			if( textfield ) textfield.restrict = r;
		}
	}
}
